using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;

namespace CKY.AgentPlatform.Mcp
{
    /// <summary>
    /// MCP服务器配置DTO
    /// </summary>
    public class McpServerConfigDto : EntityDto<string>
    {
        /// <summary>
        /// 服务器名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 服务器URL
        /// </summary>
        public string ServerUrl { get; set; }

        /// <summary>
        /// 服务器描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 连接超时时间（毫秒）
        /// </summary>
        public int ConnectTimeoutMs { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; }

        /// <summary>
        /// 服务器状态
        /// </summary>
        public string Status { get; set; }

        /// <summary>
        /// 工具数量
        /// </summary>
        public int ToolCount { get; set; }

        /// <summary>
        /// 资源数量
        /// </summary>
        public int ResourceCount { get; set; }

        /// <summary>
        /// 最后连接时间
        /// </summary>
        public DateTime? LastConnectedAt { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? LastModificationTime { get; set; }
    }

    /// <summary>
    /// 创建MCP服务器配置输入DTO
    /// </summary>
    public class CreateMcpServerConfigDto
    {
        /// <summary>
        /// 服务器名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 服务器URL
        /// </summary>
        public string ServerUrl { get; set; }

        /// <summary>
        /// 服务器描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 连接超时时间（毫秒）
        /// </summary>
        public int ConnectTimeoutMs { get; set; } = 30000;

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;
    }

    /// <summary>
    /// 更新MCP服务器配置输入DTO
    /// </summary>
    public class UpdateMcpServerConfigDto
    {
        /// <summary>
        /// 服务器名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 服务器URL
        /// </summary>
        public string ServerUrl { get; set; }

        /// <summary>
        /// 服务器描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 连接超时时间（毫秒）
        /// </summary>
        public int ConnectTimeoutMs { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; }
    }

    /// <summary>
    /// MCP服务器状态信息DTO
    /// </summary>
    public class McpServerStatusInfoDto
    {
        /// <summary>
        /// 客户端ID
        /// </summary>
        public string ClientId { get; set; }

        /// <summary>
        /// 服务器URL
        /// </summary>
        public string ServerUrl { get; set; }

        /// <summary>
        /// 是否已连接
        /// </summary>
        public bool IsConnected { get; set; }

        /// <summary>
        /// 工具数量
        /// </summary>
        public int ToolCount { get; set; }

        /// <summary>
        /// 资源数量
        /// </summary>
        public int ResourceCount { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string Status { get; set; }

        /// <summary>
        /// 最后连接时间
        /// </summary>
        public DateTime? LastConnectedAt { get; set; }

        /// <summary>
        /// 错误消息
        /// </summary>
        public string ErrorMessage { get; set; }
    }

    /// <summary>
    /// MCP服务器统计信息DTO
    /// </summary>
    public class McpServerStatsDto
    {
        /// <summary>
        /// 服务器总数
        /// </summary>
        public int TotalServers { get; set; }

        /// <summary>
        /// 已连接服务器数量
        /// </summary>
        public int ConnectedServers { get; set; }

        /// <summary>
        /// 工具总数
        /// </summary>
        public int TotalTools { get; set; }

        /// <summary>
        /// 资源总数
        /// </summary>
        public int TotalResources { get; set; }

        /// <summary>
        /// 平均响应时间
        /// </summary>
        public double AverageResponseTime { get; set; }

        /// <summary>
        /// 统计时间
        /// </summary>
        public DateTime Timestamp { get; set; }
    }

    /// <summary>
    /// 连接测试结果DTO
    /// </summary>
    public class ConnectionTestResultDto
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 工具数量
        /// </summary>
        public int ToolCount { get; set; }

        /// <summary>
        /// 资源数量
        /// </summary>
        public int ResourceCount { get; set; }

        /// <summary>
        /// 响应时间（毫秒）
        /// </summary>
        public int ResponseTimeMs { get; set; }

        /// <summary>
        /// 测试时间
        /// </summary>
        public DateTime Timestamp { get; set; }
    }

    /// <summary>
    /// 服务器工具信息DTO
    /// </summary>
    public class ServerToolInfoDto
    {
        /// <summary>
        /// 工具名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 工具描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 输入模式
        /// </summary>
        public object InputSchema { get; set; }

        /// <summary>
        /// 服务器ID
        /// </summary>
        public string ServerId { get; set; }

        /// <summary>
        /// 是否已同步
        /// </summary>
        public bool IsSynced { get; set; }

        /// <summary>
        /// 同步时间
        /// </summary>
        public DateTime? SyncedAt { get; set; }
    }

    /// <summary>
    /// 服务器资源信息DTO
    /// </summary>
    public class ServerResourceInfoDto
    {
        /// <summary>
        /// 资源URI
        /// </summary>
        public string Uri { get; set; }

        /// <summary>
        /// 资源名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 资源描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// MIME类型
        /// </summary>
        public string MimeType { get; set; }

        /// <summary>
        /// 服务器ID
        /// </summary>
        public string ServerId { get; set; }
    }

    /// <summary>
    /// 同步结果DTO
    /// </summary>
    public class SyncResultDto
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 同步的工具数量
        /// </summary>
        public int SyncedToolsCount { get; set; }

        /// <summary>
        /// 同步的资源数量
        /// </summary>
        public int SyncedResourcesCount { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public List<string> Errors { get; set; } = new List<string>();

        /// <summary>
        /// 同步时间
        /// </summary>
        public DateTime Timestamp { get; set; }
    }

    /// <summary>
    /// MCP服务器状态枚举
    /// </summary>
    public enum McpServerStatus
    {
        /// <summary>
        /// 已连接
        /// </summary>
        Connected = 0,

        /// <summary>
        /// 未连接
        /// </summary>
        Disconnected = 1,

        /// <summary>
        /// 连接中
        /// </summary>
        Connecting = 2,

        /// <summary>
        /// 错误
        /// </summary>
        Error = 3
    }
}